
//
//  XBTabBarController.m
//  微博
//
//  Created by Clement_Gu on 16/4/8.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "XBTabBarController.h"
#import "UIImage+Image.h"
#import "XBTabBar.h"
@interface XBTabBarController ()

@end

@implementation XBTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self buildViewController];
    //使用自定义的tabbar frame 是系统的frame
    XBTabBar *tabBar = [[XBTabBar alloc]initWithFrame:self.tabBar.frame];
    //因为self.tabbar 是只读的 所以用KVC来更改系统的tabbar 设置成自定义tabbar
    [self setValue:tabBar forKeyPath:@"tabBar"];
    
}

#pragma mark changetextAttributes
//设置文字颜色属性
//界面加载时候 是在viewdidload之后 viewwillapper 时候生成的
+(void)initialize
{
    //获得所有的tabbaritem外观 包括其他的tabbar里的tabbaritem
    //只要有appearance协议的都可以获得其子外观
//    UITabBarItem *item = [UITabBarItem appearance];
    //获取当前tabbar里面的item
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    //将item的属性 更改
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
    //设置其父类的一个设置文字的属性
    [item setTitleTextAttributes:dic forState:UIControlStateSelected];

    
}



#pragma  mark  -addChildViewCOntroller
-(void)buildViewController
{
    UIViewController *home = [[UIViewController alloc]init];
    [self buidOneChildViewController:home image:[UIImage imageWithOriginalName:@"tabbar_home"] slectedImage:[UIImage imageWithOriginalName:@"tabbar_home_selected"] title:@"首页"];
    home.view.backgroundColor = [UIColor whiteColor];
    
 
    //设置原始图片做一个分类
    //添加到子tabbar
    
    
    
    UIViewController *message = [[UIViewController alloc]init];
    message.view.backgroundColor = [UIColor grayColor];
    [self buidOneChildViewController:message image:[UIImage imageWithOriginalName:@"tabbar_message_center"] slectedImage:[UIImage imageWithOriginalName:@"tabbar_message_center_selected"] title:@"信息"];
    
    UIViewController *discover = [[UIViewController alloc]init];
    discover.view.backgroundColor = [UIColor orangeColor];
    [self buidOneChildViewController:discover image:[UIImage imageWithOriginalName:@"tabbar_discover"] slectedImage:[UIImage imageWithOriginalName:@"tabbar_discover_selected"] title:@"发现"];
    
    UIViewController *profile = [[UIViewController alloc]init];
    profile.view.backgroundColor = [UIColor purpleColor];
    [self buidOneChildViewController:profile image:[UIImage imageWithOriginalName:@"tabbar_profile"] slectedImage:[UIImage imageWithOriginalName:@"tabbar_profile_selected"] title:@"我"];
    
//    self.tabBar.tintColor = [UIColor orangeColor];
}

//封装每个tabbaritem
-(void)buidOneChildViewController:(UIViewController *)VC image:(UIImage *)image slectedImage:(UIImage *)selectedImage title:(NSString *)title
{

    VC.tabBarItem.title = title;
    VC.tabBarItem.image = image;
    VC.tabBarItem.selectedImage = selectedImage;
    VC.tabBarItem.badgeValue = @"10";
    [self addChildViewController:VC];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
